<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <div id="app"></div>
    <script>
        const obj = {}
        function defineReactive(obj, key, val) {
            Object.defineProperty(obj, key, {
                get() {
                    console.log(`get ${key}:${val}`);
                    return val
                },
                set(newVal) {
                    if (newVal != val) {
                        console.log(`set ${key}:${newVal}`);
                        val = newVal
                        update()
                    }
                }
            })
        }
        defineReactive(obj, 'foo', '')
        obj.foo = new Date().toLocaleTimeString()
        function update() {
            app.innerText = obj.foo

        }
        setInterval(() => {
            obj.foo = new Date().toLocaleTimeString()
        }, 1000);
    </script>
</body>

</html>